package com.six.work.mapper;

import com.six.work.entity.Announcement;
import com.six.work.entity.AnnouncementView;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AnnouncementMapper {
    @Select("SELECT announcement.*,admin.admin_name FROM announcement announcement JOIN admin admin on announcement.admin_id = admin.admin_id ORDER BY announcement.announcement_id DESC")
    List<AnnouncementView> findAllAnnouncement();

    @Select("SELECT * from announcement where announcement_id=#{announcement_id}")
    Announcement SelectAnnouncementByID(Integer announcement_id);

    @Delete("DELETE from announcement where announcement_id=#{announcement_id}")
    Integer DelAnnouncementByID(Integer announcement_id);

    @Insert("insert into announcement (announcement_id,title,comtent,admin_id,release_time) values(#{announcement_id},#{title},#{comtent},#{admin_id},#{release_time})")
    Integer insertAnnouncement(Announcement announcement);

    @Update("update announcement set admin_id=#{admin_id},announcement_id=#{announcement_id},title=#{title},comtent=#{comtent},release_time=#{release_time} where announcement_id=#{announcement_id}")
    Integer updateAnnouncement(Announcement announcement);

    @Select("SELECT  announcement.*,admin.admin_name FROM announcement announcement JOIN admin admin on announcement.admin_id = admin.admin_id " +
            "WHERE announcement.title like '%${announcementTitle}%' ORDER BY announcement.announcement_id DESC")
    List<AnnouncementView>  findAnnouncementByName(String announcementTitle);

    @Select("SELECT  announcement.*,admin.admin_name FROM announcement announcement JOIN admin admin on announcement.admin_id = admin.admin_id "+
            "WHERE announcement.title like '%${announcementTitle}%' AND admin.admin_id=#{admin_id} ORDER BY announcement.announcement_id DESC")
    List<AnnouncementView> findAnnByadIDAndannName(@Param("announcementTitle") String announcementTitle, @Param("admin_id") Integer admin_id);

}

